package 蚂蚁课堂;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo2 {
    public static void main(String[] args) {
        final CyclicBarrier cyclicBarrier=new CyclicBarrier(5, new Runnable() {
            public void run() {
                System.out.println("所有线程执行完毕，从而触发了我.......");
            }
        });
        for (int i=0;i<5;i++){
            new Thread(new Runnable() {
                public void run() {
                    try {
                        Thread.sleep(5000L);
                        System.out.println(Thread.currentThread()+" : 开始执行");
                        cyclicBarrier.await();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread()+" : 执行完毕");
                }
            },i+"").start();
        }
    }
}
